<template>
	<view>
		<!--#ifdef APP-PLUS-->
		<view class="lz-status_bar">
			<view class="lz-top_view"></view>
		</view>
		<!--#endif-->
		<!-- #ifndef MP-WEIXIN -->
		<view class="kaoshi-head">
			<view class="kaoshi-head-top">
				<view class="kaoshi-head-left" @tap="$navigateBack">
					<view class="iconfont icon-zuojiantou"></view>
				</view>
				<view class="kaoshi-head-m">排行榜</view>
			</view>
		</view>
		<!--#endif-->
		<view>
			<view class="content">
				<view class="top3" v-if="list.length != 0">
					<view class="second" v-if="list.length >= 2">
						<view class="touxiangbg">
							<image class="touxiangimg"
								:src="list[1].avatar == '' ? '../../../static/img/txk.png' : list[1].avatar" mode="">
							</image>
						</view>
						<view class="paihangname">{{list[1].nickname}}</view>
						<view class="paihangfenshu">{{list[1].score}}分</view>
						<view class="paihangtime">{{list[1].use_time}}</view>
					</view>
					<view v-else style="flex: 1;"></view>
					<view class="first">
						<view class="touxiangbg">
							<image class="touxiangimg"
								:src="list[0].avatar == '' ? '../../../static/img/txk.png' : list[0].avatar" mode="">
							</image>
						</view>
						<view class="paihangname">{{list[0].nickname}}</view>
						<view class="paihangfenshu">{{list[0].score}}分</view>
						<view class="paihangtime">{{list[0].use_time}}</view>
					</view>
					<view class="third" v-if="list.length >= 3">
						<view class="touxiangbg">
							<image class="touxiangimg"
								:src="list[2].avatar == '' ? '../../../static/img/txk.png' : list[2].avatar" mode="">
							</image>
						</view>
						<view class="paihangname">{{list[2].nickname}}</view>
						<view class="paihangfenshu">{{list[2].score}}分</view>
						<view class="paihangtime">{{list[2].use_time}}</view>
					</view>
					<view v-else style="flex: 1;"></view>
				</view>
				<view v-if="list.length >= 4" v-for="(item, index) in list" :key="item.value">
					<view v-if="index > 2" class="paimingbox"
						:class="[item.nickname == userinfo.nickname ? 'wodepaiming' : '']">
						<view class="mybox">我的排名</view>
						<view style="width: 65px;">NO.{{index + 1}}</view>
						<view class="yonghu" style="width: calc(100% - 190px)">
							<image class="touxiang"
								:src="item.avatar == '' ? '../../../static/img/txk.png' : item.avatar" mode=""></image>
							<view class="name">{{item.nickname}}</view>
						</view>
						<view class="paihangtime" style="width: 70px;text-align: right;margin-right: auto;">
							{{item.use_time}}</view>
						<view class="paihangfenshu" style="width: 52px;text-align: right;">{{item.score}}分</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex'

	export default {
		data() {
			return {
				items: ['平台考试', '机构考试'],
				current: 1,
				list: [],
				pages_params: [],
			}
		},
		onLoad(opts) {
			this.pages_params = opts
			this.getList()
		},
		onShow() {},
		mounted() {

		},
		computed: {
			...mapState(['subject', 'userinfo']),
			is_recode() {
				return (this.list.length === 0)
			}
		},
		components: {

		},
		methods: {

			async getList() {
				let res = await this.$myHttp.post({
					// 考试记录
					url: this.$myHttp.urlMap.phList,
					data: {
						exam_id: this.pages_params.exam_id
					},
					needLogin: true
				})
				if (res.code === 1) {
					let rows = res.data || []
					for (let i = 0, leng = rows.length; i < leng; i++) {
						rows[i].begin_time = this.$myUtils.$common.formatDate(rows[i].begin_time * 1000,
							'Y年M月D日 h:m:s')
						rows[i].showdetail = false
						rows[i].use_time = this.$myUtils.$common.formateSeconds(rows[i].use_time)
					}
					this.list = rows
					this.total = res.data.total
				}
			}
		}
	}
</script>
<style>
	page {
		background: #fff;
	}

	.nav {
		display: flex;
		align-items: flex-start;
		width: 92%;
		margin: 10px auto 5px;
	}

	.navbox {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.fengefu {
		width: 1px;
		height: 14px;
		margin-top: 5px;
		margin-left: 8px;
		border-left: 1px solid #bcbcbc;
	}

	.xiabiao {
		display: none;
		width: 35px;
		height: 5px;
		margin-top: 3px;
		border-radius: 5px;
		background-color: #398aff;
		box-shadow: 0px 2px 5px #6fb0ff;
	}

	.actbox {
		font-weight: bold;
	}

	.actbox .xiabiao {
		display: block !important;
	}

	.guanbi {
		width: 22px;
		height: 22px;
	}

	.content {
		width: 95%;
		margin: 10px auto 0;
	}

	.title {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 70px;
		margin-bottom: 10px;
	}

	.title .text {
		font-size: 15px;
		z-index: 9;
	}

	.background {
		width: 70px;
		height: 10px;
		margin-top: -7px;
		background-color: #e3effb;
		border-radius: 5px;
		box-shadow: 0px 1px 3px #d8e1ec;
	}

	.contentbox {
		padding: 10px 0;
		border-bottom: 1px dashed #e9e9e9;
	}

	.tousu {
		margin-top: 10px;
		float: right;
		color: #bbb;
		font-size: 14px;
	}

	.paihangtitle {
		margin: 20px auto;
		text-align: center;
		font-size: 14px;
		color: #bbb;
	}

	.top3 {
		display: flex;
		margin: 0 auto 30px;
		justify-content: space-between;
		align-items: flex-end;
	}

	.touxiangbg {
		position: relative;
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.touxiangimg {
		width: 50px;
		height: 50px;
		position: absolute;
		bottom: 3px;
		right: 24px;
		border-radius: 50%;
	}

	.first .touxiangbg {
		width: 90px;
		height: 90px;
		margin-left: 25px;
		background-image: url("");
	}

	.second .touxiangbg {
		width: 77px;
		height: 77px;
		margin-left: 20px;
		background-image: url("");
	}

	.third .touxiangbg {
		width: 77px;
		height: 77px;
		margin-left: 20px;
		background-image: url("");
	}

	.first .touxiangimg {
		width: 60px;
		height: 60px;
		border: 5px;
		right: 27px;
	}

	.first,
	.second,
	.third {
		display: flex;
		flex-direction: column;
		align-items: center;
		flex: 1;
	}

	.paihangname {
		width: 100px;
		margin-top: 5px;
		font-size: 16px;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: center;
		overflow: hidden;
	}

	.paihangfenshu {
		margin: 3px 0;
		color: #3b86fd;
		font-size: 16px;
		font-weight: bold;
	}

	.paihangtime {
		font-size: 15px;
		color: #bbb;
	}

	.paimingbox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: relative;
		padding: 5px 10px;
		border-radius: 25px;
	}

	.paimingbox .touxiang {
		width: 30px;
		height: 30px;
		margin-right: 10px;
		border-radius: 50%;
		border: solid 1px #e6e6e6;
	}

	.paimingbox .name {
		font-size: 15px;
		width: calc(100% - 30px);
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.yonghu {
		display: flex;
		align-items: center;
	}

	.mybox {
		display: none;
		padding: 1px 4px 2px;
		position: absolute;
		top: -7px;
		left: 20px;
		font-size: 12px;
		color: #fff;
		background-color: #398afd;
		border-radius: 7px 7px 7px 0;
		z-index: 999;
	}

	.wodepaiming {
		background-color: #f4f9ff;
		border: 2px solid #cde1fc;
		padding: 3px 8px;
	}

	.wodepaiming .mybox {
		display: block;
	}

	.contenttext {
		word-wrap: break-word;
		word-break: normal;
	}
</style>
